import { BaseCommand, ICmdDialogParams } from '@amcax/base';
import i18n from 'i18next';
import { useEffect, useRef } from 'react';
import CmdTangencyArcInteractor from './tangency-arc';

function TangencyArcCommand({ onClose }: ICmdDialogParams) {
  const cmdRef = useRef<CmdTangencyArcInteractor>(null);
  useEffect(() => {
    cmdRef.current = new CmdTangencyArcInteractor();
    cmdRef.current.addExit(onClose);
    return () => {
      cmdRef.current?.destroy();
      cmdRef.current = null;
    };
  }, []);
  return <></>;
}

export const cmdTangencyArc: BaseCommand = {
  id: 'CmdTangencyArc',
  label: 'command.trangency-arc',
  icon: 'commands/sketch/trangency-arc',
  group: 'sketch',
  create: function (label: string, onClose: () => void) {
    return (
      <TangencyArcCommand
        title={i18n.t(label)}
        onClose={onClose}
      />
    );
  },
};
